package com.x.erp.controller;

import java.io.IOException;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.erp.model.InsuranceClue;
import com.x.erp.rpc.InsuranceClueRpcService;
import com.x.framework.controller.BaseController;
import com.x.framework.controller.ResultCode;
import com.x.framework.controller.ResultModel;

/**
 * 保险线索Controller
 * 
 * @author pansong
 *
 */
@RestController
@RequestMapping(value = "/insuranceClue")
public class InsuranceClueController extends BaseController {

	@Reference
	private InsuranceClueRpcService insuranceClueRpcService;// 保险线索服务
	
	/**
	 * 新增保险线索
	 * 
	 * @param insuranceClue
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/insertInsuranceClue", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel insertOrUpdateRotation(InsuranceClue insuranceClue) {
		if (insuranceClue == null) {
			return new ResultModel(ResultCode.RESULT_FAIL, "保险线索信息不能为空！");
		}
		// 每一条数据至少有一个字段有值（不包括id,marketId）
		if (insuranceClue.getModelId() == null && StringUtils.isBlank(insuranceClue.getCityId())
				&& insuranceClue.getClueLicenceStatus() == null && StringUtils.isBlank(insuranceClue.getClueCarPlant())
				&& StringUtils.isBlank(insuranceClue.getClueMobile()) && StringUtils.isBlank(insuranceClue.getClueIdCard())) {
			return new ResultModel(ResultCode.RESULT_FAIL, "插入失败！");
		}
		return new ResultModel(ResultCode.RESULT_SUCCESS, "插入成功！",
				insuranceClueRpcService.insertInsuranceClue(insuranceClue));
	}

	/**
	 * 获取保险线索列表
	 * 
	 * @param insuranceClue
	 * @return
	 */
	@RequestMapping(value = "/getInsuranceClueList", method = { RequestMethod.POST, RequestMethod.GET })
	public ResultModel selectInsuranceClueList(InsuranceClue insuranceClue) {
		List<InsuranceClue> list = insuranceClueRpcService.selectInsuranceClueList(insuranceClue);
		return new ResultModel(ResultCode.RESULT_SUCCESS, "查询成功", list);
	}
}
